package com.itlong.cloud.operate.resource;

import com.itlong.cloud.POJO.DTO.operate.OperatePushInfoPageDTO;
import com.itlong.cloud.POJO.DTO.operate.OperateSavePushInfoDTO;
import com.itlong.cloud.POJO.VO.operate.OperatePushInfoOneVO;
import com.itlong.cloud.POJO.VO.operate.OperatePushInfoVO;
import com.itlong.cloud.operate.service.IOperatePushInfoService;
import com.itlong.cloud.project.operate.IOperatePushInfoServiceClient;
import com.itlong.cloud.utils.page.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

/**
 * <desc>
 *     运营-运营管理-消息推送暴露接口实现类。
 * <desc/>
 *
 * @createDate 2017/9/28.
 */
@RestController
public class OperatePushInfoServiceResource implements IOperatePushInfoServiceClient{

    @Autowired
    IOperatePushInfoService iOperatePushInfoService;

     /**
      * <desc>
      *      保存消息推送内容。
      * <desc/>
      *
      * @param  pushInfoDTO 消息推送数据传输对象
      * @return  返回影响行数
      * @author shengen.T
      * @createDate 2017/9/29
      */
    @Override
    @RequestMapping(path="/operate/marketer/pushInfo/savePushInfo",method = RequestMethod.POST)
    public Integer savePushInfo(@RequestBody OperateSavePushInfoDTO pushInfoDTO) throws Exception{

        return iOperatePushInfoService.savePushInfo(pushInfoDTO);
    }

     /**
      * <desc>
      *      修改消息推送内容。
      * <desc/>
      *
      * @param pushInfoDTO 消息推送数据传输对象
      * @return 返回影响行数
      * @author shengen.T
      * @createDate 2017/9/29
      */
    @Override
    @RequestMapping(path = "/operate/marketer/pushInfo/updatePushInfo",method = RequestMethod.POST)
    public Integer updatePushInfo(@RequestBody OperateSavePushInfoDTO pushInfoDTO) throws Exception{
        return iOperatePushInfoService.updatePushInfo(pushInfoDTO);
    }

     /**
      * <desc>
      *      批量删除消息推送内容。
      * <desc/>
      *
      * @param  pushInfoIds 消息ID列表
      * @return 返回影响行数
      * @author shengen.T
      * @createDate 2017/9/29
      */
    @Override
    @RequestMapping(path = "/operate/marketer/pushInfo/deletePushInfo", method = RequestMethod.POST)
    public Integer deletePushInfo(@RequestParam("pushInfoIds")String pushInfoIds) throws Exception{

        return  iOperatePushInfoService.deletePushInfo(pushInfoIds);
    }

     /**
      * <desc>
      *      根据消息ID获取详细内容。
      * <desc/>
      *
      * @param  pushInfoId 消息ID
      * @return 返回查询消息推送信息
      * @author shengen.T
      * @createDate 2017/9/29
      */
    @Override
    @RequestMapping(path = "/operate/marketer/pushInfo/getPushInfo/{pushInfoId}", method = RequestMethod.GET)
    public OperatePushInfoOneVO getPushInfo(@PathVariable("pushInfoId") String pushInfoId) throws  Exception{

        return iOperatePushInfoService.getPushInfo(pushInfoId);
    }

     /**
      * <desc>
      *      分页查询消息推送列表信息。
      * <desc/>
      *
      * @param  pageDTO 请求对象信息
      * @return 
      * @author shengen.T
      * @createDate 2017/9/29
      */
    @Override
    @RequestMapping(path = "/operate/marketer/pushInfo/getPushInfoPage",method = RequestMethod.POST)
    public Page<OperatePushInfoVO> getPushInfoPage(@RequestBody OperatePushInfoPageDTO pageDTO) throws Exception{
        return iOperatePushInfoService.getPushInfoPage(pageDTO);
    }


    /**
     * <desc>
     *      获取允许推送的列表信息。
     * <desc/>
     *
     * @param
     * @return  返回推送列表信息
     * @author shengen.T
     * @createDate 2017/10/27
     */
    @Override
    @RequestMapping(path = "/operate/marketer/pushInfo/getEnabledPushInfoList",method = RequestMethod.POST)
     public List<OperatePushInfoVO> getEnabledPushInfoList() throws Exception{
        return iOperatePushInfoService.getEnabledPushInfoList();
    }


    /**
     * <desc>
     *      批量设置发布状态。
     * <desc/>
     *
     * @param  pushInfoIds
     * @return 返回影响行数
     * @author shengen.T
     * @createDate 2017/10/27
     */
    @Override
    @RequestMapping(path = "/operate/marketer/pushInfo/setPushStatus/{pushInfoIds}",method = RequestMethod.POST)
    public Integer setPushStatus(@PathVariable("pushInfoIds") String pushInfoIds) throws Exception{
        return iOperatePushInfoService.setPushStatus(pushInfoIds);
    }

    /**
     * <desc>
     * 获取当前时间某项目允许推送的最新推送消息
     * <desc/>
     *
     * @param projectId 项目id
     * @return
     * @author Chunjian.G
     * @createDate 2017-11-08
     */
    @Override
    @RequestMapping(path = "/operate/marketer/pushInfo/getLatestPushContent",method = RequestMethod.POST)
    public List<String> getLatestPushContent(@RequestParam(name = "projectId") String projectId) throws Exception {
        return iOperatePushInfoService.getLatestPushContent(projectId);
    }

    /**
     * <desc>
     *      定期检测过期推送消息并改变状态。
     * <desc/>
     *
     * @param
     * @return  true更新成功 false更新失败
     * @author shengen.T
     * @createDate 2017-12-04
     */
    @Override
    @RequestMapping(path = "/operate/marketer/pushInfo/checkOverDatePushTimeTask",method = RequestMethod.POST)
    public boolean checkOverDatePushTimeTask() throws Exception{
        return iOperatePushInfoService.checkOverDatePushInfoList(new Date());
    }

    /**
     * <desc>
     *      获取当前时间某项目允许推送的最新推送消息标题
     * <desc/>
     *
     * @param projectId 项目id
     * @return
     * @author Juguang.S
     * @createDate 2019-08-28
     */
    @Override
    @RequestMapping(path = "/operate/marketer/pushInfo/getLatestPushTitle",method = RequestMethod.POST)
    public List<String> getLatestPushTitle(@RequestParam(name = "projectId") String projectId) throws Exception {
        return iOperatePushInfoService.getLatestPushTitle(projectId);
    }

    /**
     * <desc>
     *      获取app历史版本号列表
     * </desc>
     *
     * @author wangzhi
     * @createDate 2020/04/29
     */
    @Override
    @RequestMapping(path = "/operate/marketer/pushInfo/getAppVersionList", method = RequestMethod.POST)
    public List<String> getAppVersionList() throws Exception {
        return iOperatePushInfoService.getAppVersionList();
    }

    /**
     * <desc>
     *      处理旧推送数据，一次性接口，将原来的app推送数据复制一份作为小程序的推送数据，发布后第一时间运行该接口
     * </desc>
     *
     * @author wangzhi
     * @createDate 2020/04/29
     */
    @Override
    @RequestMapping(path = "/operate/marketer/pushInfo/copyAppPushInfoToMiniProgram", method = RequestMethod.POST)
    public Integer copyAppPushInfoToMiniProgram() throws Exception {
        return iOperatePushInfoService.copyAppPushInfoToMiniProgram();
    }
}
